#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2 * 1e5;

int T;
int n,a[N + 5],sum[N + 5],c[N + 5];
int dp[3005][3005];

int read(){
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar();
	return x * f;
}

signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	T = read();
	while(T--){
		memset(dp,0,sizeof(dp));
		memset(c,0,sizeof(c));
		n = read();
		int ans = 0;
		for(int i = 1;i <= n;i++){
			a[i] = read();
			sum[i] = sum[i - 1];
			if(a[i] == a[i - 1])
				c[i] = a[i],sum[i] += c[i];
		}
		
		for(int i = 1;i <= n;i++){
			dp[i][0] = sum[i];//all the same
			for(int j = 1;j < i;j++){//last insame
				dp[i][j] = max(dp[i][j],dp[j][0] + sum[i] - sum[j] - c[j + 1]);
				for(int x = 1;x < j;x++){
					int ext = sum[i] - sum[j] - c[j + 1];
					if(a[x] == a[j + 1])
						ext += a[j + 1];
					dp[i][j] = max(dp[i][j],dp[j][x] + ext);
				}
				ans = max(ans,dp[i][j]);
			}
			
		}
		
		printf("%lld\n",ans);
	}
	return 0;
}

